home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / gnu / a2_0bEmacs_bin.lha / Emacs-19.25 / info / emacs-5 (.txt) < prev    next >
GNU Info File  |  1992-02-21  |  51KB  |  873 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.43 from the
  2. input file emacs.tex.
  3.    This file documents the GNU Emacs editor.
  4.    Copyright (C) 1985, 1986, 1988 Richard M. Stallman.
  5.    Permission is granted to make and distribute verbatim copies of
  6. this manual provided the copyright notice and this permission notice
  7. are preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
  11. General Public License" are included exactly as in the original, and
  12. provided that the entire resulting derived work is distributed under
  13. the terms of a permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the sections entitled "The GNU Manifesto",
  17. "Distribution" and "GNU General Public License" may be included in a
  18. translation approved by the author instead of in the original English.
  19. File: emacs,  Node: Visiting,  Next: Saving,  Prev: File Names,  Up: Files
  20. Visiting Files
  21. ==============
  22. `C-x C-f'
  23.      Visit a file (`find-file').
  24. `C-x C-v'
  25.      Visit a different file instead of the one visited last
  26.      (`find-alternate-file').
  27. `C-x 4 C-f'
  28.      Visit a file, in another window (`find-file-other-window').  Don't
  29.      change this window.
  30.    "Visiting" a file means copying its contents into Emacs where you
  31. can edit them.  Emacs makes a new buffer for each file that you visit.
  32.  We say that the buffer is visiting the file that it was created to
  33. hold.  Emacs constructs the buffer name from the file name by throwing
  34. away the directory, keeping just the name proper.  For example, a file
  35. named `/usr/rms/emacs.tex' would get a buffer named `emacs.tex'.  If
  36. there is already a buffer with that name, a unique name is constructed
  37. by appending `<2>', `<3>', or so on, using the lowest number that
  38. makes a name that is not already in use.
  39.    Each window's mode line shows the name of the buffer that is being
  40. displayed in that window, so you can always tell what buffer you are
  41. editing.
  42.    The changes you make with Emacs are made in the Emacs buffer.  They
  43. do not take effect in the file that you visited, or any place
  44. permanent, until you "save" the buffer.  Saving the buffer means that
  45. Emacs writes the current contents of the buffer into its visited file.
  46.  *Note Saving::.
  47.    If a buffer contains changes that have not been saved, the buffer
  48. is said to be "modified".  This is important because it implies that
  49. some changes will be lost if the buffer is not saved.  The mode line
  50. displays two stars near the left margin if the buffer is modified.
  51.    To visit a file, use the command `C-x C-f' (`find-file').  Follow
  52. the command with the name of the file you wish to visit, terminated by
  53. a RET.
  54.    The file name is read using the minibuffer (*note Minibuffer::.),
  55. with defaulting and completion in the standard manner (*note File
  56. Names::.).  While in the minibuffer, you can abort `C-x C-f' by typing
  57. `C-g'.
  58.    Your confirmation that `C-x C-f' has completed successfully is the
  59. appearance of new text on the screen and a new buffer name in the mode
  60. line.  If the specified file does not exist and could not be created,
  61. or cannot be read, then an error results.  The error message is
  62. printed in the echo area, and includes the file name which Emacs was
  63. trying to visit.
  64.    If you visit a file that is already in Emacs, `C-x C-f' does not
  65. make another copy.  It selects the existing buffer containing that
  66. file.  However, before doing so, it checks that the file itself has
  67. not changed since you visited or saved it last.  If the file has
  68. changed, a warning message is printed.  *Note Simultaneous Editing:
  69. Interlocking.
  70.    What if you want to create a file?  Just visit it.  Emacs prints
  71. `(New File)' in the echo area, but in other respects behaves as if you
  72. had visited an existing empty file.  If you make any changes and save
  73. them, the file is created.
  74.    If you visit a nonexistent file unintentionally (because you typed
  75. the wrong file name), use the `C-x C-v' (`find-alternate-file')
  76. command to visit the file you wanted.  `C-x C-v' is similar to `C-x
  77. C-f', but it kills the current buffer (after first offering to save it
  78. if it is modified).  `C-x C-v' is allowed even if the current buffer
  79. is not visiting a file.
  80.    If the file you specify is actually a directory, Dired is called on
  81. that directory (*note Dired::.).  This can be inhibited by setting the
  82. variable `find-file-run-dired' to `nil'; then it is an error to try to
  83. visit a directory.
  84.    `C-x 4 f' (`find-file-other-window') is like `C-x C-f' except that
  85. the buffer containing the specified file is selected in another
  86. window.  The window that was selected before `C-x 4 f' continues to
  87. show the same buffer it was already showing.  If this command is used
  88. when only one window is being displayed, that window is split in two,
  89. with one window showing the same before as before, and the other one
  90. showing the newly requested file.  *Note Windows::.
  91.    There are two hook variables that allow extensions to modify the
  92. operation of visiting files.  Visiting a file that does not exist runs
  93. the functions in the list `find-file-not-found-hooks'; the value of
  94. this variable is expected to be a list of functions, and the functions
  95. are called one by one until one of them returns non-`nil'.  Any
  96. visiting of a file, whether extant or not, expects `find-file-hooks' to
  97. contain list of functions and calls them all, one by one.  In both
  98. cases the functions receive no arguments.  Visiting a nonexistent file
  99. runs the `find-file-not-found-hooks' first.
  100. File: emacs,  Node: Saving,  Next: Reverting,  Prev: Visiting,  Up: Files
  101. Saving Files
  102. ============
  103.    "Saving" a buffer in Emacs means writing its contents back into the
  104. file that was visited in the buffer.
  105. `C-x C-s'
  106.      Save the current buffer in its visited file (`save-buffer').
  107. `C-x s'
  108.      Save any or all buffers in their visited files
  109.      (`save-some-buffers').
  110. `M-~'
  111.      Forget that the current buffer has been changed (`not-modified').
  112. `C-x C-w'
  113.      Save the current buffer in a specified file, and record that file
  114.      as the one visited in the buffer (`write-file').
  115. `M-x set-visited-file-name'
  116.      Change file the name under which the current buffer will be saved.
  117.    When you wish to save the file and make your changes permanent, type
  118. `C-x C-s' (`save-buffer').  After saving is finished, `C-x C-s' prints
  119. a message such as
  120.      Wrote /u/rms/gnu/gnu.tasks
  121. If the selected buffer is not modified (no changes have been made in it
  122. since the buffer was created or last saved), saving is not really done,
  123. because it would have no effect.  Instead, `C-x C-s' prints a message
  124. in the echo area saying
  125.      (No changes need to be written)
  126.    The command `C-x s' (`save-some-buffers') can save any or all
  127. modified buffers.  First it asks, for each modified buffer, whether to
  128. save it.  These questions should be answered with `y' or `n'.  `C-x
  129. C-c', the key that kills Emacs, invokes `save-some-buffers' and
  130. therefore asks the same questions.
  131.    If you have changed a buffer and do not want the changes to be
  132. saved, you should take some action to prevent it.  Otherwise, each
  133. time you use `save-some-buffers' you are liable to save it by mistake.
  134.  One thing you can do is type `M-~' (`not-modified'), which clears out
  135. the indication that the buffer is modified.  If you do this, none of
  136. the save commands will believe that the buffer needs to be saved. 
  137. (`~' is often used as a mathematical symbol for `not'; thus `Meta-~'
  138. is `not', metafied.) You could also use `set-visited-file-name' (see
  139. below) to mark the buffer as visiting a different file name, one which
  140. is not in use for anything important.  Alternatively, you can undo all
  141. the changes made since the file was visited or saved, by reading the
  142. text from the file again.  This is called "reverting".  *Note
  143. Reverting::.  You could also undo all the changes by repeating the
  144. undo command `C-x u' until you have undone all the changes; but this
  145. only works if you have not made more changes than the undo mechanism
  146. can remember.
  147.    `M-x set-visited-file-name' alters the name of the file that the
  148. current buffer is visiting.  It reads the new file name using the
  149. minibuffer.  It can be used on a buffer that is not visiting a file,
  150. too.  The buffer's name is changed to correspond to the file it is now
  151. visiting in the usual fashion (unless the new name is in use already
  152. for some other buffer; in that case, the buffer name is not changed). 
  153. `set-visited-file-name' does not save the buffer in the newly visited
  154. file; it just alters the records inside Emacs so that, if you save the
  155. buffer, it will be saved in that file.  It also marks the buffer as
  156. "modified" so that `C-x C-s' will save.
  157.    If you wish to mark the buffer as visiting a different file and
  158. save it right away, use `C-x C-w' (`write-file').  It is precisely
  159. equivalent to `set-visited-file-name' followed by `C-x C-s'.  `C-x
  160. C-s' used on a buffer that is not visiting with a file has the same
  161. effect as `C-x C-w'; that is, it reads a file name, marks the buffer
  162. as visiting that file, and saves it there.  The default file name in a
  163. buffer that is not visiting a file is made by combining the buffer name
  164. with the buffer's default directory.
  165.    If Emacs is about to save a file and sees that the date of the
  166. latest version on disk does not match what Emacs last read or wrote,
  167. Emacs notifies you of this fact, because it probably indicates a
  168. problem caused by simultaneous editing and requires your immediate
  169. attention.  *Note Simultaneous Editing: Interlocking.
  170.    If the variable `require-final-newline' is non-`nil', Emacs puts a
  171. newline at the end of any file that doesn't already end in one, every
  172. time a file is saved or written.
  173.    You can implement other ways to write files, and other things to be
  174. done before writing them, using the hook variable `write-file-hooks'. 
  175. The value of this variable should be a list of Lisp functions.  When a
  176. file is to be written, the functions in the list are called, one by
  177. one, with no arguments.  If one of them returns a non-`nil' value,
  178. Emacs takes this to mean that the file has been written in some
  179. suitable fashion; the rest of the functions are not called, and normal
  180. writing is not done.
  181. * Menu:
  182. * Backup::       How Emacs saves the old version of your file.
  183. * Interlocking:: How Emacs protects against simultaneous editing
  184.                   of one file by two users.
  185. File: emacs,  Node: Backup,  Next: Interlocking,  Prev: Saving,  Up: Saving
  186. Backup Files
  187. ------------
  188.    Because Unix does not provide version numbers in file names,
  189. rewriting a file in Unix automatically destroys all record of what the
  190. file used to contain.  Thus, saving a file from Emacs throws away the
  191. old contents of the file--or it would, except that Emacs carefully
  192. copies the old contents to another file, called the "backup" file,
  193. before actually saving.  (Provided the variable `make-backup-files' is
  194. non-`nil'.  Backup files are not written if this variable is `nil').
  195.    At your option, Emacs can keep either a single backup file or a
  196. series of numbered backup files for each file that you edit.
  197.    Emacs makes a backup for a file only the first time the file is
  198. saved from one buffer.  No matter how many times you save a file, its
  199. backup file continues to contain the contents from before the file was
  200. visited.  Normally this means that the backup file contains the
  201. contents from before the current editing session; however, if you kill
  202. the buffer and then visit the file again, a new backup file will be
  203. made by the next save.
  204. * Menu:
  205. * Names: Backup Names.        How backup files are named;
  206.                 Choosing single or numbered backup files.
  207. * Deletion: Backup Deletion.    Emacs deletes excess numbered backups.
  208. * Copying: Backup Copying.    Backups can be made by copying or renaming.
  209. File: emacs,  Node: Backup Names,  Next: Backup Deletion,  Prev: Backup,  Up: Backup
  210. Single or Numbered Backups
  211. ..........................
  212.    If you choose to have a single backup file (this is the default),
  213. the backup file's name is constructed by appending `~' to the file
  214. name being edited; thus, the backup file for `eval.c' would be
  215. `eval.c~'.
  216.    If you choose to have a series of numbered backup files, backup file
  217. names are made by appending `.~', the number, and another `~' to the
  218. original file name.  Thus, the backup files of `eval.c' would be
  219. called `eval.c.~1~', `eval.c.~2~', and so on, through names like
  220. `eval.c.~259~' and beyond.
  221.    If protection stops you from writing backup files under the usual
  222. names, the backup file is written as `%backup%~' in your home
  223. directory.  Only one such file can exist, so only the most recently
  224. made such backup is available.
  225.    The choice of single backup or numbered backups is controlled by the
  226. variable `version-control'.  Its possible values are
  227.      Make numbered backups.
  228. `nil'
  229.      Make numbered backups for files that have numbered backups
  230.      already.  Otherwise, make single backups.
  231. `never'
  232.      Do not in any case make numbered backups; always make single
  233.      backups.
  234. `version-control' may be set locally in an individual buffer to
  235. control the making of backups for that buffer's file.  For example,
  236. Rmail mode locally sets `version-control' to `never' to make sure that
  237. there is only one backup for an Rmail file.  *Note Locals::.
  238. File: emacs,  Node: Backup Deletion,  Next: Backup Copying,  Prev: Backup Names,  Up: Backup
  239. Automatic Deletion of Backups
  240. .............................
  241.    To prevent unlimited consumption of disk space, Emacs can delete
  242. numbered backup versions automatically.  Generally Emacs keeps the
  243. first few backups and the latest few backups, deleting any in between.
  244.  This happens every time a new backup is made.  The two variables that
  245. control the deletion are `kept-old-versions' and `kept-new-versions'. 
  246. Their values are, respectively the number of oldest (lowest-numbered)
  247. backups to keep and the number of newest (highest-numbered) ones to
  248. keep, each time a new backup is made.  Recall that these values are
  249. used just after a new backup version is made; that newly made backup
  250. is included in the count in `kept-new-versions'.  By default, both
  251. variables are 2.
  252.    If `trim-versions-without-asking' is non-`nil', the excess middle
  253. versions are deleted without a murmur.  If it is `nil', the default,
  254. then you are asked whether the excess middle versions should really be
  255. deleted.
  256.    Dired's `.' (Period) command can also be used to delete old
  257. versions.  *Note Dired::.
  258. File: emacs,  Node: Backup Copying,  Prev: Backup Deletion,  Up: Backup
  259. Copying vs. Renaming
  260. ....................
  261.    Backup files can be made by copying the old file or by renaming it.
  262.  This makes a difference when the old file has multiple names.  If the
  263. old file is renamed into the backup file, then the alternate names
  264. become names for the backup file.  If the old file is copied instead,
  265. then the alternate names remain names for the file that you are
  266. editing, and the contents accessed by those names will be the new
  267. contents.
  268.    The method of making a backup file may also affect the file's owner
  269. and group.  If copying is used, these do not change.  If renaming is
  270. used, you become the file's owner, and the file's group becomes the
  271. default (different operating systems have different defaults for the
  272. group).
  273.    Having the owner change is usually a good idea, because then the
  274. owner always shows who last edited the file.  Also, the owners of the
  275. backups show who produced those versions.  Occasionally there is a
  276. file whose owner should not change; it is a good idea for such files
  277. to contain local variable lists to set
  278. `backup-by-copying-when-mismatch' for them alone (*note File
  279. Variables::.).
  280.    The choice of renaming or copying is controlled by three variables. 
  281. Normally, renaming is done.  If the variable `backup-by-copying' is
  282. non-`nil', copying is used.  Otherwise, if the variable
  283. `backup-by-copying-when-linked' is non-`nil', then copying is done for
  284. files that have multiple names, but renaming may still done when the
  285. file being edited has only one name.  If the variable
  286. `backup-by-copying-when-mismatch' is non-`nil', then copying is done
  287. if renaming would cause the file's owner or group to change.
  288. File: emacs,  Node: Interlocking,  Prev: Backup,  Up: Saving
  289. Protection against Simultaneous Editing
  290. ---------------------------------------
  291.    Simultaneous editing occurs when two users visit the same file,
  292. both make changes, and then both save them.  If nobody were informed
  293. that this was happening, whichever user saved first would later find
  294. that his changes were lost.  On some systems, Emacs notices
  295. immediately when the second user starts to change the file, and issues
  296. an immediate warning.  When this is not possible, or if the second
  297. user has gone on to change the file despite the warning, Emacs checks
  298. later when the file is saved, and issues a second warning when a user
  299. is about to overwrite a file containing another user's changes.  If
  300. the editing user takes the proper corrective action at this point, he
  301. can prevent actual loss of work.
  302.    When you make the first modification in an Emacs buffer that is
  303. visiting a file, Emacs records that you have locked the file.  (It
  304. does this by writing another file in a directory reserved for this
  305. purpose.)  The lock is removed when you save the changes.  The idea is
  306. that the file is locked whenever the buffer is modified.  If you begin
  307. to modify the buffer while the visited file is locked by someone else,
  308. this constitutes a collision, and Emacs asks you what to do.  It does
  309. this by calling the Lisp function `ask-user-about-lock', which you can
  310. redefine for the sake of customization.  The standard definition of
  311. this function asks you a question and accepts three possible answers:
  312.      Steal the lock.  Whoever was already changing the file loses the
  313.      lock, and you gain the lock.
  314.      Proceed.  Go ahead and edit the file despite its being locked by
  315.      someone else.
  316.      Quit.  This causes an error (`file-locked') and the modification
  317.      you were trying to make in the buffer does not actually take
  318.      place.
  319.    Note that locking works on the basis of a file name; if a file has
  320. multiple names, Emacs does not realize that the two names are the same
  321. file and cannot prevent two user from editing it simultaneously under
  322. different names.  However, basing locking on names means that Emacs
  323. can interlock the editing of new files that will not really exist
  324. until they are saved.
  325.    Some systems are not configured to allow Emacs to make locks.  On
  326. these systems, Emacs cannot detect trouble in advance, but it still can
  327. detect it in time to prevent you from overwriting someone else's
  328. changes.
  329.    Every time Emacs saves a buffer, it first checks the
  330. last-modification date of the existing file on disk to see that it has
  331. not changed since the file was last visited or saved.  If the date
  332. does not match, it implies that changes were made in the file in some
  333. other way, and these changes are about to be lost if Emacs actually
  334. does save.  To prevent this, Emacs prints a warning message and asks
  335. for confirmation before saving.  Occasionally you will know why the
  336. file was changed and know that it does not matter; then you can answer
  337. `yes' and proceed.  Otherwise, you should cancel the save with `C-g'
  338. and investigate the situation.
  339.    The first thing you should do when notified that simultaneous
  340. editing has already taken place is to list the directory with `C-u C-x
  341. C-d' (*note Directory Listing: ListDir.).  This will show the file's
  342. current author.  You should attempt to contact him to warn him not to
  343. continue editing.  Often the next step is to save the contents of your
  344. Emacs buffer under a different name, and use `diff' to compare the two
  345. files.
  346.    Simultaneous editing checks are also made when you visit with `C-x
  347. C-f' a file that is already visited and when you start to modify a
  348. file.  This is not strictly necessary, but it can cause you to find
  349. out about the problem earlier, when perhaps correction takes less work.
  350. File: emacs,  Node: Reverting,  Next: Auto Save,  Prev: Saving,  Up: Files
  351. Reverting a Buffer
  352. ==================
  353.    If you have made extensive changes to a file and then change your
  354. mind about them, you can get rid of them by reading in the previous
  355. version of the file.  To do this, use `M-x revert-buffer', which
  356. operates on the current buffer.  Since this is a very dangerous thing
  357. to do, you must confirm it with `yes'.
  358.    If the current buffer has been auto-saved more recently than it has
  359. been saved for real, `revert-buffer' offers to read the auto save file
  360. instead of the visited file (*note Auto Save::.).  This question comes
  361. before the usual request for confirmation, and demands `y' or `n' as
  362. an answer.  If you have started to type `yes' for confirmation without
  363. realizing that the other question was going to be asked, the `y' will
  364. answer that question, but the `es' will not be valid confirmation.  So
  365. you will have a chance to cancel the operation with `C-g' and try it
  366. again with the answers that you really intend.
  367.    `revert-buffer' keeps point at the same distance (measured in
  368. characters) from the beginning of the file.  If the file was edited
  369. only slightly, you will be at approximately the same piece of text
  370. after reverting as before.  If you have made drastic changes, the same
  371. value of point in the old file may address a totally different piece
  372. of text.
  373.    A buffer reverted from its visited file is marked "not modified"
  374. until another change is made.
  375.    Some kinds of buffers whose contents reflect data bases other than
  376. files, such as Dired buffers, can also be reverted.  For them,
  377. reverting means recalculating their contents from the appropriate data
  378. base.  Buffers created randomly with `C-x b' cannot be reverted;
  379. `revert-buffer' reports an error when asked to do so.
  380. File: emacs,  Node: Auto Save,  Next: ListDir,  Prev: Reverting,  Up: Files
  381. Auto-Saving: Protection Against Disasters
  382. =========================================
  383.    Emacs saves all the visited files from time to time (based on
  384. counting your keystrokes) without being asked.  This is called
  385. "auto-saving".  It prevents you from losing more than a limited amount
  386. of work if the system crashes.
  387.    When Emacs determines that it is time for auto-saving, each buffer
  388. is considered, and is auto-saved if auto-saving is turned on for it
  389. and it has been changed since the last time it was auto-saved.  If any
  390. auto-saving is done, the message `Auto-saving...' is displayed in the
  391. echo area until auto-saving is finished.  Errors occurring during
  392. auto-saving are caught so that they do not interfere with the
  393. execution of commands you have been typing.
  394. * Menu:
  395. * Files: Auto Save Files.
  396. * Control: Auto Save Control.
  397. * Recover::        Recovering text from auto-save files.
  398. File: emacs,  Node: Auto Save Files,  Next: Auto Save Control,  Prev: Auto Save,  Up: Auto Save
  399. Auto-Save Files
  400. ---------------
  401.    Auto-saving does not normally save in the files that you visited,
  402. because it can be very undesirable to save a program that is in an
  403. inconsistent state when you have made half of a planned change. 
  404. Instead, auto-saving is done in a different file called the "auto-save
  405. file", and the visited file is changed only when you request saving
  406. explicitly (such as with `C-x C-s').
  407.    Normally, the auto-save file name is made by appending `#' to the
  408. front and rear of the visited file name.  Thus, a buffer visiting file
  409. `foo.c' would be auto-saved in a file `#foo.c#'.  Most buffers that
  410. are not visiting files are auto-saved only if you request it
  411. explicitly; when they are auto-saved, the auto-save file name is made
  412. by appending `#%' to the front and `#' to the rear of buffer name. 
  413. For example, the `*mail*' buffer in which you compose messages to be
  414. sent is auto-saved in a file named `#%*mail*#'.  Auto-save file names
  415. are made this way unless you reprogram parts of Emacs to do something
  416. different (the functions `make-auto-save-file-name' and
  417. `auto-save-file-name-p').  The file name to be used for auto-saving in
  418. a buffer is calculated when auto-saving is turned on in that buffer.
  419.    If you want auto-saving to be done in the visited file, set the
  420. variable `auto-save-visited-file-name' to be non-`nil'.  In this mode,
  421. there is really no difference between auto-saving and explicit saving.
  422.    A buffer's auto-save file is deleted when you save the buffer in its
  423. visited file.  To inhibit this, set the variable
  424. `delete-auto-save-files' to `nil'.  Changing the visited file name
  425. with `C-x C-w' or `set-visited-file-name' renames any auto-save file
  426. to go with the new visited name.
  427. File: emacs,  Node: Auto Save Control,  Next: Recover,  Prev: Auto Save Files,  Up: Auto Save
  428. Controlling Auto-Saving
  429. -----------------------
  430.    Each time you visit a file, auto-saving is turned on for that file's
  431. buffer if the variable `auto-save-default' is non-`nil' (but not in
  432. batch mode; *note Entering Emacs::.).  The default for this variable is
  433. `t', so auto-saving is the usual practice for file-visiting buffers. 
  434. Auto-saving can be turned on or off for any existing buffer with the
  435. command `M-x auto-save-mode'.  Like other minor mode commands, `M-x
  436. auto-save-mode' turns auto-saving on with a positive argument, off
  437. with a zero or negative argument; with no argument, it toggles.
  438.    Emacs does auto-saving periodically based on counting how many
  439. characters you have typed since the last time auto-saving was done. 
  440. The variable `auto-save-interval' specifies how many characters there
  441. are between auto-saves.  By default, it is 300.  Emacs also auto-saves
  442. whenever you call the function `do-auto-save'.
  443.    Emacs also does auto-saving whenever it gets a fatal error.  This
  444. includes killing the Emacs job with a shell command such as `kill
  445. %emacs', or disconnecting a phone line or network connection.
  446. File: emacs,  Node: Recover,  Prev: Auto Save Control,  Up: Auto Save
  447. Recovering Data from Auto-Saves
  448. -------------------------------
  449.    The way to use the contents of an auto-save file to recover from a
  450. loss of data is with the command `M-x recover-file RET FILE RET'. 
  451. This visits FILE and then (after your confirmation) restores the
  452. contents from from its auto-save file `#FILE#'.  You can then save
  453. with `C-x C-s' to put the recovered text into FILE itself.  For
  454. example, to recover file `foo.c' from its auto-save file `#foo.c#', do:
  455.      M-x recover-file RET foo.c RET
  456.      C-x C-s
  457.    Before asking for confirmation, `M-x recover-file' displays a
  458. directory listing describing the specified file and the auto-save file,
  459. so you can compare their sizes and dates.  If the auto-save file is
  460. older, `M-x recover-file' does not offer to read it.
  461.    Auto-saving is disabled by `M-x recover-file' because using this
  462. command implies that the auto-save file contains valuable data from a
  463. past session.  If you save the data in the visited file and then go on
  464. to make new changes, you should turn auto-saving back on with `M-x
  465. auto-save-mode'.
  466. File: emacs,  Node: ListDir,  Next: Dired,  Prev: Auto Save,  Up: Files
  467. Listing a File Directory
  468. ========================
  469.    Files are classified by Unix into "directories".  A "directory
  470. listing" is a list of all the files in a directory.  Emacs provides
  471. directory listings in brief format (file names only) and verbose format
  472. (sizes, dates, and authors included).
  473. `C-x C-d DIR-OR-PATTERN'
  474.      Print a brief directory listing (`list-directory').
  475. `C-u C-x C-d DIR-OR-PATTERN'
  476.      Print a verbose directory listing.
  477.    The command to print a directory listing is `C-x C-d'
  478. (`list-directory').  It reads using the minibuffer a file name which
  479. is either a directory to be listed or a wildcard-containing pattern
  480. for the files to be listed.  For example,
  481.      C-x C-d /u2/emacs/etc RET
  482. lists all the files in directory `/u2/emacs/etc'.  An example of
  483. specifying a file name pattern is
  484.      C-x C-d /u2/emacs/src/*.c RET
  485.    Normally, `C-x C-d' prints a brief directory listing containing just
  486. file names.  A numeric argument (regardless of value) tells it to
  487. print a verbose listing (like `ls -l').
  488.    The text of a directory listing is obtained by running `ls' in an
  489. inferior process.  Two Emacs variables control the switches passed to
  490. `ls': `list-directory-brief-switches' is a string giving the switches
  491. to use in brief listings (`"-CF"' by default), and
  492. `list-directory-verbose-switches' is a string giving the switches to
  493. use in a verbose listing (`"-l"' by default).
  494. File: emacs,  Node: Dired,  Next: Misc File Ops,  Prev: ListDir,  Up: Files
  495. Dired, the Directory Editor
  496. ===========================
  497.    Dired makes it easy to delete or visit many of the files in a single
  498. directory at once.  It makes an Emacs buffer containing a listing of
  499. the directory.  You can use the normal Emacs commands to move around
  500. in this buffer, and special Dired commands to operate on the files.
  501. * Menu:
  502. * Enter: Dired Enter.         How to invoke Dired.
  503. * Edit: Dired Edit.           Editing the Dired buffer.
  504. * Deletion: Dired Deletion.   Deleting files with Dired.
  505. * Immed: Dired Immed.         Other file operations through Dired.
  506. File: emacs,  Node: Dired Enter,  Next: Dired Edit,  Prev: Dired,  Up: Dired
  507. Entering Dired
  508. --------------
  509.    To invoke dired, do `C-x d' or `M-x dired'.  The command reads a
  510. directory name or wildcard file name pattern as a minibuffer argument
  511. just like the `list-directory' command, `C-x C-d'.  Where `dired'
  512. differs from `list-directory' is in naming the buffer after the
  513. directory name or the wildcard pattern used for the listing, and
  514. putting the buffer into Dired mode so that the special commands of
  515. Dired are available in it.  The variable `dired-listing-switches' is a
  516. string used as an argument to `ls' in making the directory; this string
  517. must contain `-l'.
  518.    To display the Dired buffer in another window rather than in the
  519. selected window, use `C-x 4 d' (`dired-other-window)' instead of `C-x
  520. File: emacs,  Node: Dired Edit,  Next: Dired Deletion,  Prev: Dired Enter,  Up: Dired
  521. Editing in Dired
  522. ----------------
  523.    Once the Dired buffer exists, you can switch freely between it and
  524. other Emacs buffers.  Whenever the Dired buffer is selected, certain
  525. special commands are provided that operate on files that are listed. 
  526. The Dired buffer is "read-only", and inserting text in it is not
  527. useful, so ordinary printing characters such as `d' and `x' are used
  528. for Dired commands.  Most Dired commands operate on the file described
  529. by the line that point is on.  Some commands perform operations
  530. immediately; others "flag" the file to be operated on later.
  531.    Most Dired commands that operate on the current line's file also
  532. treat a numeric argument as a repeat count, meaning to act on the
  533. files of the next few lines.  A negative argument means to operate on
  534. the files of the preceding lines, and leave point on the first of
  535. those lines.
  536.    All the usual Emacs cursor motion commands are available in Dired
  537. buffers.  Some special purpose commands are also provided.  The keys
  538. `C-n' and `C-p' are redefined so that they try to position the cursor
  539. at the beginning of the filename on the line, rather than at the
  540. beginning of the line.
  541.    For extra convenience, SPC and `n' in Dired are equivalent to
  542. `C-n'.  `p' is equivalent to `C-p'.  Moving by lines is done so often
  543. in Dired that it deserves to be easy to type.  DEL (move up and
  544. unflag) is often useful simply for moving up.
  545.    The `g' command in Dired runs `revert-buffer' to reinitialize the
  546. buffer from the actual disk directory and show any changes made in the
  547. directory by programs other than Dired.  All deletion flags in the
  548. Dired buffer are lost when this is done.
  549. File: emacs,  Node: Dired Deletion,  Next: Dired Immed,  Prev: Dired Edit,  Up: Dired
  550. Deleting Files with Dired
  551. -------------------------
  552.    The primary use of Dired is to flag files for deletion and then
  553. delete them.
  554.      Flag this file for deletion.
  555.      Remove deletion-flag on this line.
  556. `DEL'
  557.      Remove deletion-flag on previous line, moving point to that line.
  558.      Delete the files that are flagged for deletion.
  559.      Flag all auto-save files (files whose names start and end with
  560.      `#') for deletion (*note Auto Save::.).
  561.      Flag all backup files (files whose names end with `~') for
  562.      deletion (*note Backup::.).
  563. `. (Period)'
  564.      Flag excess numeric backup files for deletion.  The oldest and
  565.      newest few backup files of any one file are exempt; the middle
  566.      ones are flagged.
  567.    You can flag a file for deletion by moving to the line describing
  568. the file and typing `d' or `C-d'.  The deletion flag is visible as a
  569. `D' at the beginning of the line.  Point is moved to the beginning of
  570. the next line, so that repeated `d' commands flag successive files.
  571.    The files are flagged for deletion rather than deleted immediately
  572. to avoid the danger of deleting a file accidentally.  Until you direct
  573. Dired to delete the flagged files, you can remove deletion flags using
  574. the commands `u' and DEL.  `u' works just like `d', but removes flags
  575. rather than making flags.  DEL moves upward, removing flags; it is
  576. like `u' with numeric argument automatically negated.
  577.    To delete the flagged files, type `x'.  This command first displays
  578. a list of all the file names flagged for deletion, and requests
  579. confirmation with `yes'.  Once you confirm, all the flagged files are
  580. deleted, and their lines are deleted from the text of the Dired
  581. buffer.  The shortened Dired buffer remains selected.  If you answer
  582. `no' or quit with `C-g', you return immediately to Dired, with the
  583. deletion flags still present and no files actually deleted.
  584.    The `#', `~' and `.' commands flag many files for deletion, based
  585. on their names.  These commands are useful precisely because they do
  586. not actually delete any files; you can remove the deletion flags from
  587. any flagged files that you really wish to keep.
  588.    `#' flags for deletion all files that appear to have been made by
  589. auto-saving (that is, files whose names begin and end with `#').  `~'
  590. flags for deletion all files that appear to have been made as backups
  591. for files that were edited (that is, files whose names end with `~').
  592.    `.' (Period) flags just some of the backup files for deletion: only
  593. numeric backups that are not among the oldest few nor the newest few
  594. backups of any one file.  Normally `dired-kept-versions' (not
  595. `kept-new-versions'; that applies only when saving) specifies the
  596. number of newest versions of each file to keep, and
  597. `kept-old-versions' specifies the number of oldest versions to keep. 
  598. Period with a positive numeric argument, as in `C-u 3 .', specifies the
  599. number of newest versions to keep, overriding `dired-kept-versions'. 
  600. A negative numeric argument overrides `kept-old-versions', using minus
  601. the value of the argument to specify the number of oldest versions of
  602. each file to keep.
  603. File: emacs,  Node: Dired Immed,  Prev: Dired Deletion,  Up: Dired
  604. Immediate File Operations in Dired
  605. ----------------------------------
  606.    Some file operations in Dired take place immediately when they are
  607. requested.
  608.      Copies the file described on the current line.  You must supply a
  609.      file name to copy to, using the minibuffer.
  610.      Visits the file described on the current line.  It is just like
  611.      typing `C-x C-f' and supplying that file name.  If the file on
  612.      this line is a subdirectory, `f' actually causes Dired to be
  613.      invoked on that subdirectory.  *Note Visiting::.
  614.      Like `f', but uses another window to display the file's buffer. 
  615.      The Dired buffer remains visible in the first window.  This is
  616.      like using `C-x 4 C-f' to visit the file.  *Note Windows::.
  617.      Renames the file described on the current line.  You must supply
  618.      a file name to rename to, using the minibuffer.
  619.      Views the file described on this line using `M-x view-file'. 
  620.      Viewing a file is like visiting it, but is slanted toward moving
  621.      around in the file conveniently and does not allow changing the
  622.      file.  *Note View File: Misc File Ops.  Viewing a file that is a
  623.      directory runs Dired on that directory.
  624. File: emacs,  Node: Misc File Ops,  Prev: Dired,  Up: Files
  625. Miscellaneous File Operations
  626. =============================
  627.    Emacs has commands for performing many other operations on files. 
  628. All operate on one file; they do not accept wild card file names.
  629.    `M-x view-file' allows you to scan or read a file by sequential
  630. screenfuls.  It reads a file name argument using the minibuffer.  After
  631. reading the file into an Emacs buffer, `view-file' reads and displays
  632. one windowful.  You can then type SPC to scroll forward one windowful,
  633. or DEL to scroll backward.  Various other commands are provided for
  634. moving around in the file, but none for changing it; type `C-h' while
  635. viewing for a list of them.  They are mostly the same as normal Emacs
  636. cursor motion commands.  To exit from viewing, type `C-c'.
  637.    `M-x insert-file' inserts a copy of the contents of the specified
  638. file into the current buffer at point, leaving point unchanged before
  639. the contents and the mark after them.  *Note Mark::.
  640.    `M-x write-region' is the inverse of `M-x insert-file'; it copies
  641. the contents of the region into the specified file.  `M-x
  642. append-to-file' adds the text of the region to the end of the
  643. specified file.
  644.    `M-x delete-file' deletes the specified file, like the `rm' command
  645. in the shell.  If you are deleting many files in one directory, it may
  646. be more convenient to use Dired (*note Dired::.).
  647.    `M-x rename-file' reads two file names OLD and NEW using the
  648. minibuffer, then renames file OLD as NEW.  If a file named NEW already
  649. exists, you must confirm with `yes' or renaming is not done; this is
  650. because renaming causes the old meaning of the name NEW to be lost. 
  651. If OLD and NEW are on different file systems, the file OLD is copied
  652. and deleted.
  653.    The similar command `M-x add-name-to-file' is used to add an
  654. additional name to an existing file without removing its old name. 
  655. The new name must belong on the same file system that the file is on.
  656.    `M-x copy-file' reads the file OLD and writes a new file named NEW
  657. with the same contents.  Confirmation is required if a file named NEW
  658. already exists, because copying has the consequence of overwriting the
  659. old contents of the file NEW.
  660.    `M-x make-symbolic-link' reads two file names OLD and LINKNAME, and
  661. then creates a symbolic link named LINKNAME and pointing at OLD.  The
  662. effect is that future attempts to open file LINKNAME will refer to
  663. whatever file is named OLD at the time the opening is done, or will
  664. get an error if the name OLD is not in use at that time.  Confirmation
  665. is required when creating the link if LINKNAME is in use.  Note that
  666. not all systems support symbolic links.
  667. File: emacs,  Node: Buffers,  Next: Windows,  Prev: Files,  Up: Top
  668. Using Multiple Buffers
  669. **********************
  670.    The text you are editing in Emacs resides in an object called a
  671. "buffer".  Each time you visit a file, a buffer is created to hold the
  672. file's text.  Each time you invoke Dired, a buffer is created to hold
  673. the directory listing.  If you send a message with `C-x m', a buffer
  674. named `*mail*' is used to hold the text of the message.  When you ask
  675. for a command's documentation, that appears in a buffer called
  676. `*Help*'.
  677.    At any time, one and only one buffer is "selected".  It is also
  678. called the "current buffer".  Often we say that a command operates on
  679. "the buffer" as if there were only one; but really this means that the
  680. command operates on the selected buffer (most commands do).
  681.    When Emacs makes multiple windows, each window has a chosen buffer
  682. which is displayed there, but at any time only one of the windows is
  683. selected and its chosen buffer is the selected buffer.  Each window's
  684. mode line displays the name of the buffer that the window is
  685. displaying (*note Windows::.).
  686.    Each buffer has a name, which can be of any length, and you can
  687. select any buffer by giving its name.  Most buffers are made by
  688. visiting files, and their names are derived from the files' names. 
  689. But you can also create an empty buffer with any name you want.  A
  690. newly started Emacs has a buffer named `*scratch*' which can be used
  691. for evaluating Lisp expressions in Emacs.  The distinction between
  692. upper and lower case matters in buffer names.
  693.    Each buffer records individually what file it is visiting, whether
  694. it is modified, and what major mode and minor modes are in effect in it
  695. (*note Major Modes::.).  Any Emacs variable can be made "local to" a
  696. particular buffer, meaning its value in that buffer can be different
  697. from the value in other buffers.  *Note Locals::.
  698. * Menu:
  699. * Select Buffer::   Creating a new buffer or reselecting an old one.
  700. * List Buffers::    Getting a list of buffers that exist.
  701. * Misc Buffer::     Renaming; changing read-onliness; copying text.
  702. * Kill Buffer::     Killing buffers you no longer need.
  703. * Several Buffers:: How to go through the list of all buffers
  704.                      and operate variously on several of them.
  705. File: emacs,  Node: Select Buffer,  Next: List Buffers,  Prev: Buffers,  Up: Buffers
  706. Creating and Selecting Buffers
  707. ==============================
  708. `C-x b BUFFER RET'
  709.      Select or create a buffer named BUFFER (`switch-to-buffer').
  710. `C-x 4 b BUFFER RET'
  711.      Similar but select a buffer named BUFFER in another window
  712.      (`switch-to-buffer-other-window').
  713.    To select the buffer named BUFNAME, type `C-x b BUFNAME RET'.  This
  714. is the command `switch-to-buffer' with argument BUFNAME.  You can use
  715. completion on an abbreviation for the buffer name you want (*note
  716. Completion::.).  An empty argument to `C-x b' specifies the most
  717. recently selected buffer that is not displayed in any window.
  718.    Most buffers are created by visiting files, or by Emacs commands
  719. that want to display some text, but you can also create a buffer
  720. explicitly by typing `C-x b BUFNAME RET'.  This makes a new, empty
  721. buffer which is not visiting any file, and selects it for editing. 
  722. Such buffers are used for making notes to yourself.  If you try to
  723. save one, you are asked for the file name to use.  The new buffer's
  724. major mode is determined by the value of `default-major-mode' (*note
  725. Major Modes::.).
  726.    Note that `C-x C-f', and any other command for visiting a file, can
  727. also be used to switch buffers.  *Note Visiting::.
  728. File: emacs,  Node: List Buffers,  Next: Misc Buffer,  Prev: Select Buffer,  Up: Buffers
  729. Listing Existing Buffers
  730. ========================
  731. `C-x C-b'
  732.      List the existing buffers (`list-buffers').
  733.    To print a list of all the buffers that exist, type `C-x C-b'. 
  734. Each line in the list shows one buffer's name, major mode and visited
  735. file.  `*' at the beginning of a line indicates the buffer is
  736. "modified".  If several buffers are modified, it may be time to save
  737. some with `C-x s' (*note Saving::.).  `%' indicates a read-only
  738. buffer.  `.' marks the selected buffer.  Here is an example of a
  739. buffer list:
  740.       MR Buffer         Size  Mode           File
  741.       -- ------         ----  ----           ----
  742.      .*  emacs.tex      383402 Texinfo       /u2/emacs/man/emacs.tex
  743.          *Help*         1287  Fundamental
  744.          files.el       23076 Emacs-Lisp     /u2/emacs/lisp/files.el
  745.        % RMAIL          64042 RMAIL          /u/rms/RMAIL
  746.       *% man            747   Dired
  747.          net.emacs      343885 Fundamental   /u/rms/net.emacs
  748.          fileio.c       27691 C              /u2/emacs/src/fileio.c
  749.          NEWS           67340 Text           /u2/emacs/etc/NEWS
  750.          *scratch*       0     Lisp Interaction
  751. Note that the buffer `*Help*' was made by a help request; it is not
  752. visiting any file.  The buffer `man' was made by Dired on the
  753. directory `/u2/emacs/man/'.
  754. File: emacs,  Node: Misc Buffer,  Next: Kill Buffer,  Prev: List Buffers,  Up: Buffers
  755. Miscellaneous Buffer Operations
  756. ===============================
  757. `C-x C-q'
  758.      Toggle read-only status of buffer (`toggle-read-only').
  759. `M-x rename-buffer'
  760.      Change the name of the current buffer.
  761. `M-x view-buffer'
  762.      Scroll through a buffer.
  763.    A buffer can be "read-only", which means that commands to change its
  764. text are not allowed.  Normally, read-only buffers are made by
  765. subsystems such as Dired and Rmail that have special commands to
  766. operate on the text; a read-only buffer is also made if you visit a
  767. file that is protected so you cannot write it.  If you wish to make
  768. changes in a read-only buffer, use the command `C-x C-q'
  769. (`toggle-read-only').  It makes a read-only buffer writable, and makes
  770. a writable buffer read-only.  This works by setting the variable
  771. `buffer-read-only', which has a local value in each buffer and makes
  772. the buffer read-only if its value is non-`nil'.
  773.    `M-x rename-buffer' changes the name of the current buffer.  Specify
  774. the new name as a minibuffer argument.  There is no default.  If you
  775. specify a name that is in use for some other buffer, an error happens
  776. and no renaming is done.
  777.    `M-x view-buffer' is much like `M-x view-file' (*note Misc File
  778. Ops::.) except that it examines an already existing Emacs buffer. 
  779. View mode provides commands for scrolling through the buffer
  780. conveniently but not for changing it. When you exit View mode, the
  781. value of point that resulted from your perusal remains in effect.
  782.    The commands `C-x a' (`append-to-buffer') and `M-x insert-buffer'
  783. can be used to copy text from one buffer to another.  *Note
  784. Accumulating Text::.
  785. File: emacs,  Node: Kill Buffer,  Next: Several Buffers,  Prev: Misc Buffer,  Up: Buffers
  786. Killing Buffers
  787. ===============
  788.    After you use Emacs for a while, you may accumulate a large number
  789. of buffers.  You may then find it convenient to eliminate the ones you
  790. no longer need.  There are several commands provided for doing this.
  791. `C-x k'
  792.      Kill a buffer, specified by name (`kill-buffer').
  793. `M-x kill-some-buffers'
  794.      Offer to kill each buffer, one by one.
  795.    `C-x k' (`kill-buffer') kills one buffer, whose name you specify in
  796. the minibuffer.  The default, used if you type just RET in the
  797. minibuffer, is to kill the current buffer.  If the current buffer is
  798. killed, another buffer is selected; a buffer that has been selected
  799. recently but does not appear in any window now is chosen to be
  800. selected.  If the buffer being killed is modified (has unsaved
  801. editing) then you are asked to confirm with `yes' before the buffer is
  802. killed.
  803.    The command `M-x kill-some-buffers' asks about each buffer, one by
  804. one.  An answer of `y' means to kill the buffer.  Killing the current
  805. buffer or a buffer containing unsaved changes selects a new buffer or
  806. asks for confirmation just like `kill-buffer'.
  807. File: emacs,  Node: Several Buffers,  Prev: Kill Buffer,  Up: Buffers
  808. Operating on Several Buffers
  809. ============================
  810.    The "buffer-menu" facility is like a "Dired for buffers"; it allows
  811. you to request operations on various Emacs buffers by editing an Emacs
  812. buffer containing a list of them.  You can save buffers, kill them
  813. (here called "deleting" them, for consistency with Dired), or display
  814. them.
  815. `M-x buffer-menu'
  816.      Begin editing a buffer listing all Emacs buffers.
  817.    The command `buffer-menu' writes a list of all Emacs buffers into
  818. the buffer `*Buffer List*', and selects that buffer in Buffer Menu
  819. mode.  The buffer is read-only, and can only be changed through the
  820. special commands described in this section.  Most of these commands
  821. are graphic characters.  The usual Emacs cursor motion commands can be
  822. used in the `*Buffer List*' buffer.  The following special commands
  823. apply to the buffer described on the current line.
  824.      Request to delete (kill) the buffer, then move down.  The request
  825.      shows as a `D' on the line, before the buffer name.  Requested
  826.      deletions take place when the `x' command is used.
  827.      Synonym for `d'.
  828. `C-d'
  829.      Like `d' but move up afterwards instead of down.
  830.      Request to save the buffer.  The request shows as an `S' on the
  831.      line.  Requested saves take place when the `x' command is used. 
  832.      You may request both saving and deletion for the same buffer.
  833.      Mark buffer "unmodified".  The command `~' does this immediately
  834.      when typed.
  835.      Perform previously requested deletions and saves.
  836.      Remove any request made for the current line, and move down.
  837. `DEL'
  838.      Move to previous line and remove any request made for that line.
  839.    All the commands that put in or remove flags to request later
  840. operations also move down a line, and accept a numeric argument as a
  841. repeat count, unless otherwise specified.
  842.    There are also special commands to use the buffer list to select
  843. another buffer, and to specify one or more other buffers for display
  844. in additional windows.
  845.      Select the buffer in a full-screen window.  This command takes
  846.      effect immediately.
  847.      Immediately set up two windows, with this buffer in one, and the
  848.      previously selected buffer (aside from the buffer `*Buffer List*')
  849.      in the other.
  850.      Immediately select the buffer in place of the `*Buffer List*'
  851.      buffer.
  852.      Immediately select the buffer in another window as if by `C-x 4
  853.      b', leaving `*Buffer List*' visible.
  854.      Immediately select this buffer, and also display in other windows
  855.      any buffers previously flagged with the `m' command.  If there
  856.      are no such buffers, this command is equivalent to `1'.
  857.      Flag this buffer to be displayed in another window if the `q'
  858.      command is used.  The request shows as a `>' at the beginning of
  859.      the line.  The same buffer may not have both a delete request and
  860.      a display request.
  861.    All that `buffer-menu' does directly is create and select a suitable
  862. buffer, and turn on Buffer Menu mode.  Everything else described above
  863. is implemented by the special commands provided in Buffer Menu mode. 
  864. One consequence of this is that you can switch from the `*Buffer List*'
  865. buffer to another Emacs buffer, and edit there.  You can reselect the
  866. `buffer-menu' buffer later, to perform the operations already
  867. requested, or you can kill it, or pay no further attention to it.
  868.    The only difference between `buffer-menu' and `list-buffers' is
  869. that `buffer-menu' selects the `*Buffer List*' buffer and
  870. `list-buffers' does not.  If you run `list-buffers' (that is, type
  871. `C-x C-b') and select the buffer list manually, you can use all of the
  872. commands described here.
  873.